package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// SuccessList 列表成功返回
func SuccessList(c *gin.Context, list any, total int64) {
	data := make(map[string]interface{})
	data["list"] = list
	data["total"] = total
	c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "ok", "data": data})
}

// Success 成功直接返回
func Success(c *gin.Context, data any, msg string) {

	c.JSON(http.StatusOK, gin.H{"code": 0, "msg": msg, "data": data})
}

// SuccessData 返显 返回data下增加row 方便后期增加其他参数扩展
func SuccessData(c *gin.Context, data any, msg string) {
	row := make(map[string]any)
	row["row"] = data
	c.JSON(http.StatusOK, gin.H{"code": 0, "msg": msg, "data": row})
}

// Fail 失败
func Error(c *gin.Context, msg string, err ...any) {
	c.JSON(http.StatusOK, gin.H{"code": 1, "msg": msg, "err": err})
}

// NotLogin 未登录
func NotLogin(c *gin.Context, code int, msg string) {
	c.JSON(http.StatusOK, gin.H{"code": code, "msg": msg, "data": ""})
	c.Abort()
}

// NotAuthority 无权访问
func NotAuthority(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"code": 401, "msg": "无权访问", "data": ""})
	c.Abort()
}
